package com.hx.dc.entity;

import com.hx.dc.service.SimpleOrderService;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2019/2/26 0026.
 */

public class Dingshan extends QuartzJobBean {
    @Autowired
    SimpleOrderService simpleOrderService;
    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        //从job上下文中获取spring上下文信息
        ApplicationContext applicationContext = (ApplicationContext) context.getJobDetail().getJobDataMap()
                .get("applicationContext");
        SimpleOrderService simpleOrderService=(SimpleOrderService) applicationContext.getBean("simpleOrderService");
        List<SimpleOrder> list=simpleOrderService.xian();
        System.out.println("说"+list.toString());
        for(SimpleOrder attribute : list) {
            Date makedate=attribute.getMakeTime();
            System.out.println("制单时间"+makedate.getDate());
            //Date paydate=attribute.getPayTime();
            //long tt=paydate.getTime();
           // System.out.println(tt);
            Date tt=new Date();
            System.out.println(tt.toString());
            long nd = 1000 * 24 * 60 * 60;
            long nh = 1000 * 60 * 60;
            long nm = 1000 * 60;
            // long ns = 1000;
            // 获得两个时间的毫秒时间差异
            long diff = tt.getTime() - makedate.getTime();
            // 计算差多少天
            long day = diff / nd;
            // 计算差多少小时
            long hour = diff % nd / nh;
            // 计算差多少分钟
            long min = diff % nd % nh / nm;
            // 计算差多少秒//输出结果
            // long sec = diff % nd % nh % nm / ns;
            System.out.println( day + "天" + hour + "小时" + min + "分钟");
          if (day>0){
              System.out.println("shanchu");
             simpleOrderService.delete(attribute);
          }else {
              if (hour>3){
                  System.out.println("hour");
                  simpleOrderService.delete(attribute);
              }else {

              }
          }
        }

    }
}
